<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>基于HTTP插件的模拟设备数据上报 | 美的楼宇科技研究院</title>
    <meta name="generator" content="VuePress 1.9.5">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="iBUILDING作为智慧建筑的数字践行者，致力于用数字的眼光建筑世界。以科技赋能楼宇，构建数字建筑生态，共创更美好的智慧空间。Make iBUILDING come TRUE。">
    <meta name="keywords" content="iBUILDING,ibuilding">
    <meta name="theme-color" content="#11a8cd">
    <meta name="baidu-site-verification" content="code-j1XZ46JIBR">
    
    <link rel="preload" href="/assets/css/0.styles.af9b49f9.css" as="style"><link rel="preload" href="/assets/js/app.ffe9b366.js" as="script"><link rel="preload" href="/assets/js/2.9760a328.js" as="script"><link rel="preload" href="/assets/js/12.5d62fb57.js" as="script"><link rel="prefetch" href="/assets/js/10.1ca8e9a5.js"><link rel="prefetch" href="/assets/js/11.f84ca260.js"><link rel="prefetch" href="/assets/js/13.3fd35f26.js"><link rel="prefetch" href="/assets/js/14.d428d44b.js"><link rel="prefetch" href="/assets/js/15.752b1e82.js"><link rel="prefetch" href="/assets/js/16.f33da816.js"><link rel="prefetch" href="/assets/js/17.4a25f92e.js"><link rel="prefetch" href="/assets/js/18.3ad538ff.js"><link rel="prefetch" href="/assets/js/19.4957cef9.js"><link rel="prefetch" href="/assets/js/20.264d8716.js"><link rel="prefetch" href="/assets/js/21.2e6c7b77.js"><link rel="prefetch" href="/assets/js/22.4abc22b5.js"><link rel="prefetch" href="/assets/js/23.52e85444.js"><link rel="prefetch" href="/assets/js/24.ae24e643.js"><link rel="prefetch" href="/assets/js/25.5596a9ad.js"><link rel="prefetch" href="/assets/js/26.d952969d.js"><link rel="prefetch" href="/assets/js/27.7711bd91.js"><link rel="prefetch" href="/assets/js/3.0b2e2ac4.js"><link rel="prefetch" href="/assets/js/4.d41f70ee.js"><link rel="prefetch" href="/assets/js/5.603be3f5.js"><link rel="prefetch" href="/assets/js/6.36f53e66.js"><link rel="prefetch" href="/assets/js/7.8566b5df.js"><link rel="prefetch" href="/assets/js/8.82830ba8.js"><link rel="prefetch" href="/assets/js/9.d949e13c.js">
    <link rel="stylesheet" href="/assets/css/0.styles.af9b49f9.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="https://static-btri.midea.com/mfs/1001/1656483801940.svg" alt="美的楼宇科技研究院" class="logo"> <span class="site-name can-hide">美的楼宇科技研究院</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📖开源项目" class="dropdown-title"><!----> <span class="title" style="display:;">📖开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/driver-box/" class="nav-link">driver-box</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发者社区" class="dropdown-title"><!----> <span class="title" style="display:;">开发者社区</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/about.html" class="nav-link">技术博客</a></li><li class="dropdown-item"><!----> <a href="https://openibuilding.midea.com/home" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开放平台
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源仓库" class="dropdown-title"><!----> <span class="title" style="display:;">开源仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/iBUILDING-X" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📖开源项目" class="dropdown-title"><!----> <span class="title" style="display:;">📖开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/driver-box/" class="nav-link">driver-box</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发者社区" class="dropdown-title"><!----> <span class="title" style="display:;">开发者社区</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/about.html" class="nav-link">技术博客</a></li><li class="dropdown-item"><!----> <a href="https://openibuilding.midea.com/home" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开放平台
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源仓库" class="dropdown-title"><!----> <span class="title" style="display:;">开源仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/iBUILDING-X" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/blog/about.html" class="sidebar-link">技术团队</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>边缘网关</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/edge-env/" class="sidebar-link">边缘环境搭建</a></li><li><a href="/pages/faeaa1/" class="sidebar-link">基于NanoPi的边缘网关镜像制作</a></li><li><a href="/pages/416f35/" aria-current="page" class="active sidebar-link">基于HTTP插件的模拟设备数据上报</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/416f35/#背景" class="sidebar-link">背景</a></li><li class="sidebar-sub-header level2"><a href="/pages/416f35/#实现" class="sidebar-link">实现</a></li><li class="sidebar-sub-header level2"><a href="/pages/416f35/#步骤" class="sidebar-link">步骤</a></li><li class="sidebar-sub-header level2"><a href="/pages/416f35/#测试" class="sidebar-link">测试</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/416f35/#定时上报" class="sidebar-link">定时上报</a></li></ul></li></ul></li><li><a href="/pages/9caacc/" class="sidebar-link">云边集群快速搭建的解决方案</a></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>blog</span></li><li data-v-06225672><span data-v-06225672>边缘网关</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="javascript:;" data-v-06225672>李行</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-06-07</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">基于HTTP插件的模拟设备数据上报<!----></h1> <div class="page-slot page-slot-top">
    <div class="wwads-cn wwads-horizontal page-wwads" data-id="136"></div>
    <style>
      .page-wwads{
        width:100%!important;
        min-height: 0;
        margin: 0;
      }
      .page-wwads .wwads-img img{
        width:80px!important;
      }
      .page-wwads .wwads-poweredby{
        width: 40px;
        position: absolute;
        right: 25px;
        bottom: 3px;
      }
      .wwads-content .wwads-text, .page-wwads .wwads-text{
        height: 100%;
        padding-top: 5px;
        display: block;
      }
  </style>
  </div> <div class="theme-vdoing-content content__default"><h1 id="基于http插件的模拟设备数据上报"><a href="#基于http插件的模拟设备数据上报" class="header-anchor">#</a> 基于HTTP插件的模拟设备数据上报</h1> <h2 id="背景"><a href="#背景" class="header-anchor">#</a> 背景</h2> <p>在真实设备未准备就绪的情况下（采供中、未安装等原因），为了云边协同开发，边缘需要提前模拟设备数据，提供给云端。<br>
此时就需要通过模拟程序，进行设备的点位上报，从而摆脱开发者对真实设备的依赖，大大提高了云边协同开发效率。</p> <h2 id="实现"><a href="#实现" class="header-anchor">#</a> 实现</h2> <p>通过 <strong>driver-box</strong> 的 HTTP_Server 插件，可以快速实现模拟设备点位上报。</p> <h2 id="步骤"><a href="#步骤" class="header-anchor">#</a> 步骤</h2> <ol><li>克隆 driver-box 项目，清空 driver-config 目录下文件</li></ol> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> clone https://gitee.com/iBUILDING-X/driver-box.git
<span class="token builtin class-name">cd</span> driver-box <span class="token operator">&amp;&amp;</span> <span class="token function">rm</span> <span class="token parameter variable">-rf</span> driver-config/*
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ol start="2"><li>在 driver-config 目录下新建虚拟设备文件夹、配置文件以及脚本文件</li></ol> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token builtin class-name">cd</span> driver-config

<span class="token comment"># virtualDeviceHttpServer 为虚拟设备文件夹名称，可自定义</span>
<span class="token function">mkdir</span> virtualDeviceHttpServer

<span class="token builtin class-name">cd</span> virtualDeviceHttpServer

<span class="token comment"># 配置文件及脚本文件</span>
<span class="token function">touch</span> config.json
<span class="token function">touch</span> converter.lua
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><ol start="3"><li>修改 config.json 文件，示例如下：</li></ol> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
	<span class="token property">&quot;deviceModels&quot;</span><span class="token operator">:</span><span class="token punctuation">[</span>
		<span class="token punctuation">{</span>
			<span class="token property">&quot;name&quot;</span><span class="token operator">:</span><span class="token string">&quot;testModel&quot;</span><span class="token punctuation">,</span>
			<span class="token property">&quot;modelId&quot;</span><span class="token operator">:</span> <span class="token string">&quot;testModel&quot;</span><span class="token punctuation">,</span>
			<span class="token property">&quot;description&quot;</span><span class="token operator">:</span><span class="token string">&quot;测试模型&quot;</span><span class="token punctuation">,</span>
			<span class="token property">&quot;devicePoints&quot;</span><span class="token operator">:</span><span class="token punctuation">[</span>
				<span class="token punctuation">{</span>
					<span class="token property">&quot;name&quot;</span><span class="token operator">:</span><span class="token string">&quot;onOff&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;description&quot;</span><span class="token operator">:</span><span class="token string">&quot;开关&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;valueType&quot;</span><span class="token operator">:</span><span class="token string">&quot;int&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;readWrite&quot;</span><span class="token operator">:</span><span class="token string">&quot;R&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;reportMode&quot;</span><span class="token operator">:</span><span class="token string">&quot;change&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;timerReport&quot;</span><span class="token operator">:</span><span class="token string">&quot;15m&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;realReport&quot;</span><span class="token operator">:</span><span class="token boolean">true</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">]</span><span class="token punctuation">,</span>
			<span class="token property">&quot;deviceActions&quot;</span><span class="token operator">:</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
			<span class="token property">&quot;devices&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
				<span class="token punctuation">{</span>
					<span class="token property">&quot;name&quot;</span><span class="token operator">:</span><span class="token string">&quot;test_device_1&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;description&quot;</span><span class="token operator">:</span><span class="token string">&quot;测试设备1&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;connectionKey&quot;</span><span class="token operator">:</span><span class="token string">&quot;common&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;protocol&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
				<span class="token punctuation">}</span><span class="token punctuation">,</span>
				<span class="token punctuation">{</span>
					<span class="token property">&quot;name&quot;</span><span class="token operator">:</span><span class="token string">&quot;test_device_2&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;description&quot;</span><span class="token operator">:</span><span class="token string">&quot;测试设备2&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;connectionKey&quot;</span><span class="token operator">:</span><span class="token string">&quot;common&quot;</span><span class="token punctuation">,</span>
					<span class="token property">&quot;protocol&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">]</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">]</span><span class="token punctuation">,</span>
	<span class="token property">&quot;timerTasks&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
	<span class="token property">&quot;connections&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
		<span class="token property">&quot;common&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
			<span class="token property">&quot;host&quot;</span><span class="token operator">:</span> <span class="token string">&quot;0.0.0.0&quot;</span><span class="token punctuation">,</span>
			<span class="token property">&quot;port&quot;</span><span class="token operator">:</span> <span class="token number">8080</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token property">&quot;protocolName&quot;</span><span class="token operator">:</span><span class="token string">&quot;http_server&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br></div></div><ol start="4"><li>修改 converter.lua 脚本文件，示例如下：</li></ol> <div class="language-lua line-numbers-mode"><pre class="language-lua"><code><span class="token keyword">local</span> json <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&quot;json&quot;</span><span class="token punctuation">)</span>

<span class="token comment">-- decode 请求数据解码</span>
<span class="token keyword">function</span> <span class="token function">decode</span><span class="token punctuation">(</span>raw<span class="token punctuation">)</span>
    <span class="token keyword">local</span> data <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">decode</span><span class="token punctuation">(</span>raw<span class="token punctuation">)</span>
    math<span class="token punctuation">.</span><span class="token function">randomseed</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">time</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token keyword">if</span> data<span class="token punctuation">.</span>method <span class="token operator">==</span> <span class="token string">&quot;GET&quot;</span> <span class="token keyword">and</span> data<span class="token punctuation">.</span>path <span class="token operator">==</span> <span class="token string">&quot;/report&quot;</span> <span class="token keyword">then</span>
        <span class="token keyword">local</span> devices <span class="token operator">=</span> <span class="token punctuation">{</span>
            <span class="token punctuation">{</span>
                <span class="token punctuation">[</span><span class="token string">&quot;device_name&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;test_device_1&quot;</span><span class="token punctuation">,</span>
                <span class="token punctuation">[</span><span class="token string">&quot;values&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
                    <span class="token punctuation">{</span>
                        <span class="token punctuation">[</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;onOff&quot;</span><span class="token punctuation">,</span>
                        <span class="token punctuation">[</span><span class="token string">&quot;value&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token punctuation">{</span>
                <span class="token punctuation">[</span><span class="token string">&quot;device_name&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;test_device_2&quot;</span><span class="token punctuation">,</span>
                <span class="token punctuation">[</span><span class="token string">&quot;values&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
                    <span class="token punctuation">{</span>
                        <span class="token punctuation">[</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;onOff&quot;</span><span class="token punctuation">,</span>
                        <span class="token punctuation">[</span><span class="token string">&quot;value&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">return</span> json<span class="token punctuation">.</span><span class="token function">encode</span><span class="token punctuation">(</span>devices<span class="token punctuation">)</span>
    <span class="token keyword">end</span>

    <span class="token keyword">return</span> <span class="token string">&quot;[]&quot;</span>
<span class="token keyword">end</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div><ol start="5"><li>安装依赖并运行</li></ol> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 切换到项目根目录，安装依赖</span>
go mod veondr

<span class="token comment"># 运行 docker 环境</span>
<span class="token function">docker</span> compose up <span class="token parameter variable">-d</span>

<span class="token comment"># 运行 driver-box 服务</span>
go run main.go
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="测试"><a href="#测试" class="header-anchor">#</a> 测试</h2> <p>通过发送 get 请求即可触发模拟数据的点位上报，默认情况下访问连接：http://127.0.0.1:8080/report 即可进行单次上报</p> <h3 id="定时上报"><a href="#定时上报" class="header-anchor">#</a> 定时上报</h3> <p>通过 crontab 可以实现定时上报功能</p> <blockquote><p>仅支持 Linux 系统</p></blockquote> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">sudo</span> <span class="token function">vi</span> /etc/contab

<span class="token comment"># 追加内容如下：</span>
* * * * * root <span class="token function">curl</span> http://127.0.0.1:8080/report
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></div></div>  <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/06/16, 10:44:51</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/faeaa1/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">基于NanoPi的边缘网关镜像制作</div></a> <a href="/pages/9caacc/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">云边集群快速搭建的解决方案</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/faeaa1/" class="prev">基于NanoPi的边缘网关镜像制作</a></span> <span class="next"><a href="/pages/9caacc/">云边集群快速搭建的解决方案</a>→
      </span></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"><a href="https://gitee.com/iBUILDING-X" title="Gitee" target="_blank" class="iconfont icon-gitee"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2023-2023
    <span>iBUILDING</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.ffe9b366.js" defer></script><script src="/assets/js/2.9760a328.js" defer></script><script src="/assets/js/12.5d62fb57.js" defer></script>
  </body>
</html>
